package DAO;

import Damain.emp;
import Utils.JdbcUtils;

import java.sql.*;

public class EmpUpdateDaoImpl implements EmpUpdateDao {
    /**
     * 逻辑层实现数据更新
     *
     * @param emp
     */
    private Connection connection = null;
    private PreparedStatement statement = null;


    @Override
    public void Update(emp emp) {
        try {
            connection = JdbcUtils.getConnection();
            String sql = "UPDATE t_emp SET ename = ?, age = ?,sex = ?, sal = ?, birthday = ?, edate =? WHERE id =?";

            statement = connection.prepareStatement(sql);
            statement.setString(1, emp.getEname());
            statement.setInt(2, emp.getAge());
            statement.setString(3, emp.getSex());
            statement.setInt(4, emp.getSal());
            statement.setString(5, emp.getBirthday());
            statement.setString(6, emp.getEdate());
            statement.setInt(7,emp.getId());
            //执行
            statement.executeUpdate();
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            JdbcUtils.close(connection, statement);
        }
    }
}
